from django.db import models


# 用户model
class User(models.Model):
    # 用户ID
    user_id = models.IntegerField(primary_key=True, unique=True, verbose_name='用户ID')
    # 用户名称
    user_name = models.CharField(max_length=30, verbose_name='用户名称')
    # 用户密码
    user_password = models.CharField(max_length=30, verbose_name='用户密码')
    # 创建时间
    gmt_time = models.DateTimeField(verbose_name='创建时间')


# 蘑菇箱model
class MushBox(models.Model):
    # 蘑菇箱ID
    mb_id = models.IntegerField(primary_key=True, unique=True, verbose_name='蘑菇箱ID')
    # 用户ID
    userid = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户ID')
    # 蘑菇箱名称
    mb_name = models.CharField(max_length=30, verbose_name='蘑菇箱名称')
    # 蘑菇箱描述
    mb_des = models.CharField(max_length=200, verbose_name='蘑菇箱描述')
    # 创建时间
    gmt_time = models.DateTimeField(verbose_name='创建时间')


# 上传数据集合model
class UpdateDataSet(models.Model):
    # 数据ID
    data_id = models.AutoField(primary_key=True, verbose_name='数据ID')
    # 蘑菇箱ID
    # mb_id = models.ForeignKey(MushBox, to_field=MushBox.mb_id, on_delete=models.CASCADE)
    mbid = models.ForeignKey(MushBox, on_delete=models.CASCADE, verbose_name='蘑菇箱ID')
    # 温度
    mb_temp = models.FloatField(verbose_name='温度')
    # 湿度
    mb_hum = models.FloatField(verbose_name='湿度')
    # 是否长出来
    mb_isgrow = models.IntegerField(verbose_name='左边的蘑菇是否成熟')
    # 是否成熟
    mb_isqipe = models.IntegerField(verbose_name='右边的蘑菇是否成熟')
    # 是否开启通风风扇
    mb_enfan = models.IntegerField(verbose_name='是否开启通风风扇')
    # 是否开启冷风扇
    mb_encoldfan = models.IntegerField(verbose_name="是否开启冷风扇")
    # 是否开启热风扇
    mb_enhotfan = models.IntegerField(verbose_name='是否开启热风扇')
    # 是否开启加湿器
    mb_enhum = models.IntegerField(verbose_name='是否开启加湿器')
    # 数据上传时间
    mb_time = models.DateTimeField(verbose_name="数据上传时间")


class MbControl(models.Model):
    # 蘑菇箱ID
    mbid = models.ForeignKey(MushBox, primary_key=True, on_delete=models.CASCADE, verbose_name='蘑菇箱ID')
    # 控制模式
    mb_model = models.IntegerField(verbose_name="控制模式")
    # 温度上限
    mb_temmax = models.FloatField(verbose_name="温度上限")
    # 温度下限
    mb_temmin = models.FloatField(verbose_name="温度下限")
    # 湿度上限
    mb_hummax = models.FloatField(verbose_name="湿度上限")
    # 湿度下限
    mb_hummin = models.FloatField(verbose_name="湿度下限")
    # 是否开启风扇
    mb_enfan = models.IntegerField(verbose_name="是否开启风扇")
    # 是否开启热风扇
    mb_enhotfan = models.IntegerField(verbose_name="是否开启热风扇")
    # 是否开启冷风扇
    mb_encoldfan = models.IntegerField(verbose_name="是否开启冷风扇")
    # 是否开启加湿器
    mb_enhum = models.IntegerField(verbose_name="是否开启加湿器")
    # 加湿器运行时间
    mb_waterruntime = models.IntegerField(verbose_name="加湿器运行时间")
    # 加湿器间隔时间
    mb_waterspan = models.IntegerField(verbose_name="加湿器间隔时间")
